	var gold_top = "";
	var gold_bottom = "";
	var intervalId = "";
	var arraySize = "";
	var changeSec = "6000";
	var leftTime;
	$().ready(function(){
		leftTime = $("#tlsEndTime").text()-$("#systemTime").text();
		setInterval(countLeft,1000);
		$("#main-gold-1").hide();
		$("div.sel-box > a").eq(0).attr("class","sel-num1");
		//random show maingold
		arraySize = $("div.sel-box > a").length;
		var maingoldNum = $.random($("div.sel-box > a").length);
		$("#main-gold-" + (maingoldNum + 1)).show();
		$("div.sel-box > a").eq(maingoldNum).attr("class",$("div.sel-box > a").eq(maingoldNum).attr("class") + "f");
		init5Tabs();
		//每六秒自動跳tab,当滑鼠移到上面时则不执行
		$("a[class*='sel-num']").each(function(){
			$(this).mouseenter(function(){
				gold_top = $(this);
				clearInterval(intervalId);
			});
			$(this).mouseleave(function(){
				gold_top = "";
				intervalId = setInterval(showRotatingTab,changeSec);
			});
		});
		$("div[id*='main-gold-']").each(function(){
			$(this).mouseenter(function(){
				gold_bottom = $(this);
				clearInterval(intervalId);
			});
			$(this).mouseleave(function(){
				gold_bottom = "";
				intervalId = setInterval(showRotatingTab,changeSec);
			});
		});
		
		//random hotsale
		var hotsaleSize = parseInt($(":div[id*=hotsale_box_]").size());
		var hotsale_cur = $.random(hotsaleSize)+1;
		$("#hotsale_box_" + hotsale_cur).show();
		//hotsale
	    $("#hotsale_left").click(function(){
	      if(hotsale_cur>1){
	        hotsale_cur--;
	        $(":div[id*=hotsale_box_]").hide();
	        var hotSaleBox = $("#hotsale_box_"+hotsale_cur);
	        hotSaleBox.show();
			var hotSaleImages = hotSaleBox.find("img");
			hotSaleImages.each(function(){
				if ($(this).attr('src') != $(this).attr('original')) {
					$(this).attr('src', $(this).attr('original'));
				}
			});
	      }else{
	    	  $("#hotsale_box_1").hide(); 
	    	  var hotSaleBox = $("#hotsale_box_"+hotsaleSize);
	          hotSaleBox.show();
	          var hotSaleImages = hotSaleBox.find("img");
	          hotSaleImages.each(function(){
	        	  if ($(this).attr('src') != $(this).attr('original')) {
	        		  $(this).attr('src', $(this).attr('original'));
	        	  }
	          });
	    	  hotsale_cur = hotsaleSize;
	      }
	    });
	    $("#hotsale_right").click(function(){
	      if(hotsale_cur<$(":div[id*=hotsale_box_]").size()){
	        hotsale_cur++;
	        $(":div[id*=hotsale_box_]").hide();
	        var hotSaleBox = $("#hotsale_box_"+hotsale_cur);
	        hotSaleBox.show();
	  		var hotSaleImages = hotSaleBox.find("img");
	  		hotSaleImages.each(function(){
	  			if ($(this).attr('src') != $(this).attr('original')) {
	  				$(this).attr('src', $(this).attr('original'));
	  			}
	  		});
	      }else{
	    	  $("#hotsale_box_" + hotsaleSize).hide(); 
	    	  var hotSaleBox = $("#hotsale_box_1");  
	          hotSaleBox.show();
	          var hotSaleImages = hotSaleBox.find("img");
	          hotSaleImages.each(function(){
	        	  if ($(this).attr('src') != $(this).attr('original')) {
	        		  $(this).attr('src', $(this).attr('original'));
	        	  }
	          });
	    	  hotsale_cur = 1;
	      }
	    });
	    //random brand
		var brand_cur = $.random(10)+1;
		$("#brandProd_" + brand_cur).show();
		$("#brandLink_" + brand_cur).attr('class', 'fo');
		$(":a[id*=brandLink_]").mouseenter(function(){
			$(":a[id*=brandProd_]").hide();
			$(":a[id*=brandLink_]").removeAttr('class');
			brand_cur = $(this).attr('id').split('_')[1];
			$(this).attr('class', 'fo');
			$("#brandProd_" + brand_cur).show();
			$("#brandProd_" + brand_cur+" > li > a > img").each(function(){
				if ($(this).attr('src') != $(this).attr('original')) {
					$(this).attr('src', $(this).attr('original'));
				}
			});
			traceVirtualPage('/brand.mo?hpp=ItbBrand_'+brand_cur);
		});
	});
	function mainGoldRotating(){
		//共有幾個tab
		var myImg = new Array(arraySize);
		for( i = 1; i = arraySize; i++){
			myImg[i-1] = i;
		}
		//要取幾張來播放
		var playImg = new Array(arraySize);
		//目前播放到第幾張
		var nowIndex;
		$("div.sel-box > a").each(function(index,item){
			if ( $(this).attr("class").indexOf("f") != -1 ){
				nowIndex = index;
			}
		});
		//從allImg中取出N張放到myImg裡面
		for(var i = 0;i < playImg.length;i++){
			playImg[i] = myImg[nowIndex];
			nowIndex++;
			if (nowIndex > (arraySize-1)) nowIndex = 0;
		}
	}
	function showRotatingTab(){
		//共有幾個tab
		var myImg = new Array(arraySize);
		for( i = 0 ; i < arraySize ; i++ ){
			myImg[i] = i;
		}
		//要取幾張來播放
		var playImg = new Array(arraySize);
		//目前播放到第幾張
		var nowIndex = 0;
		var tempNowIndex = 0;
		$("div.sel-box > a").each(function(index,item){
			var thisClass = $(this).attr("class");
			if ( thisClass.indexOf("f") > -1 ){
				nowIndex = index;
				$(this).attr("class","sel-num" + (index+1));
			}
		});
		tempNowIndex = nowIndex;
		$("div[id*='main-gold-']").each(function(){
			$(this).hide();
		});
		tempNowIndex++;
		if (tempNowIndex > (arraySize-1)) tempNowIndex = 0;
		//eq從0開始算
		$("div.sel-box > a").eq(myImg[tempNowIndex]).attr("class",$("div.sel-box > a").eq(myImg[tempNowIndex]).attr("class") + "f");
		//traceVirtualPage(_admain[parseInt(myImg[tempNowIndex],10)]);
		$("#main-gold-" + (parseInt(myImg[tempNowIndex],10)+1)).show();
	}	
	function init5Tabs(){
		if ( gold_bottom == "" && gold_top == "" )
			intervalId = setInterval(showRotatingTab,changeSec);
	}
	function countLeft(){
		if(leftTime>=0){
			var showText;
			var tmp = leftTime%3600;
			var h = (leftTime-tmp)/3600;
			showText = add0(h)+":";
			var tmp2 = tmp%60;
			var m = (tmp-tmp2)/60;
			showText = showText+add0(m)+":"+add0(tmp2);
			$("#tlsLeftTime").text(showText);
		}else if(leftTime == -5){
			window.location.reload();
		}
		if(leftTime > -5){
			leftTime--;
		}
	}
	function add0(num){
		if(num<10)
			return "0"+num;
		return num;
	}